using System.Collections.Generic;
using System.IO;
using System.Linq;

using NUnit.Framework;
using NUnit.Framework.SyntaxHelpers;

using Pronghorn.Core;

using TestDoubles;

namespace ViewEngine_Tests
{
	[TestFixture]
	public class SkinParser_Test
	{
		#region Public Methods

		[Test]
		public void Check_that_the_parser_can_process_a_valid_skin()
		{
			var lines = StubSkinLocator.GetView();
			IList<INodeVisitor> visitors = new List<INodeVisitor>
			                                   {
			                                       new TextNodeVisitor(),
			                                       new ForEachNodeVisitor(),
			                                       new IfNodeVisitor(),
			                                       new ScriptNodeVisitor(),
			                                       new MetaNodeVisitor(),
			                                       new StyleNodeVisitor(),
			                                       new AreaNodeVisitor()
			                                   };
			ISkinLocator skinLocator = new StubSkinLocator();
			ISkinParser parser = new CSharpSkinParser(skinLocator, visitors);
			TextWriter sw = new StringWriter();
			   
			parser.Parse(sw);

			var result = sw.ToString();
			Assert.That(result, Is.Not.Empty);
		}

		#endregion Public Methods
	}
}

namespace ViewEngine_Tests
{
	public class Skins_Basic_Home : SkinBase
	{
		#region Constructors

		public Skins_Basic_Home(IProngHornSkinContext skinContext, ICollectionRenderer collectionRenderer, IFileLinkRenderer scriptRenderer, IFileLinkRenderer cssRenderer)
			: base(skinContext, collectionRenderer, scriptRenderer,cssRenderer)
		{
		}

		#endregion Constructors

		#region Protected Methods

		protected override void GenerateHtml(TextWriter writer)
		{
			writer.Write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">");
			writer.Write("<html>");
			writer.Write("	<head>");
			writer.Write(string.Format("		<title>{0}</title>", Model.PageTitle));
			RenderCollection(Model.GetMetaTags(), writer);
			//RenderCollection(Model.Scripts, writer);
			//RenderCollection(Model.StyleSheets, writer);
			writer.Write("	</head>");
			writer.Write("	<body>");
			var scenes = Model.Data.GetIEnumerable("scenes");
			if (scenes != null)
			{
			    foreach (var scene in scenes)
			    {
			        writer.Write(string.Format("     <img src=\"{0}\" title=\"{1}\" border=\"0\"/>", Model.Data.GetString(scene, "scene.src"), Model.Data.GetString(scene, "scene.title")));
			    }
			}
			writer.Write("	    <div class=\"className\" onClick=\"alert('my name here');\">");
			writer.Write("	        <div>");
			var arealeftnavbar = Model.Areas.FirstOrDefault(a => a.Name.ToLower() == "leftnavbar");
			RenderCollection((IList<IRenderable>)arealeftnavbar.Layout, writer);
			writer.Write("            </div>");
			writer.Write("	        <div>");
			var areacontent = Model.Areas.FirstOrDefault(a => a.Name.ToLower() == "content");
			RenderCollection((IList<IRenderable>)areacontent.Layout, writer);
			writer.Write("            </div>");
			writer.Write("	        <div>");
			var arearightnavbar = Model.Areas.FirstOrDefault(a => a.Name.ToLower() == "rightnavbar");
			RenderCollection((IList<IRenderable>)arearightnavbar.Layout, writer);
			writer.Write("            </div>");
			writer.Write("	    </div>");
			writer.Write("	</body>");
			writer.Write("</html>");
		}

		#endregion Protected Methods
	}
}